﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAPbouiCOM;
using SAPbobsCOM;
using System.Collections;

namespace BoAddonBiz_FreightForwarder.Land
{
    [BoAddonBiz_FreightForwarder.BusinessBase.ControlB1Form(IsNew = true, FormType = B1FormTypes.ado_AVA_LN_Storage)]
    public class B1Form_Storage_Land : B1Form_BaseOperationSon
    {
        #region private/public properties


        public override string FatherField
        {
            get { return "U_IsWarehouse"; }
        }

        public override string FatherUDS
        {
            get { return "OSTG_UID"; }
        }

        public override string ThisTableName
        {
            get { return "@AVA_LN_OSTG"; }
        }

        public override string ThisObjectCode
        {
            get { return "AVA_LN_Storage"; }
        }

        public override string ThisSubTableName
        {
            get { return "@AVA_LN_STG1"; }
        }
        public override string ThisSubTableName2
        {
            get { return null; }
        }
        int CargoCurrentOffset = 0;//货物信息的当前行
        #endregion

        #region constructor
        public B1Form_Storage_Land()
            : base()
        {
            this.frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_Storage_frm_ItemEvent);
            this.frm_ChooseFormListEvent += new SAPBoAddon.IB1FormEvents.B1ChooseFormListEventEventHandler(B1Form_Storage_frm_ChooseFormListEvent);
            this.frm_FormDataEvent += new SAPBoAddon.IB1FormEvents.B1FormDataEventEventHandler(B1Form_Storage_frm_FormDataEvent);
        }

        void B1Form_Storage_frm_FormDataEvent(SAPBoAddon.B1AddonBase.B1BusinessObjectInfo pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction == false)
            {
                if (pVal.EventType == BoEventTypes.et_FORM_DATA_LOAD && pVal.ActionSuccess)
                {
                    Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", 0);/*货物显示行号、总行数*/
                }
            }
        }
        #endregion

        #region events
        void B1Form_Storage_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
        {
            if (pVal.Before_Action)
            {
                SAPbouiCOM.ChooseFromList cfl = this.CurrentForm.ChooseFromLists.Item(pVal.ChooseFromListUID);
                SAPbouiCOM.Conditions cons;
                SAPbouiCOM.Condition con;
                switch (pVal.ChooseFromListUID)
                {
                    case "CFL_Card":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "CardType";
                        con.CondVal = "S";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                }
            }
            else
            {
                if (pVal.Action_Success)
                {
                    if (pVal.ChooseFromListUID == "CFL_Card")//委托单位
                    {
                        SAPbouiCOM.DBDataSource dbds = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_LN_STG1");
                        dbds.SetValue("U_DelCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_delName", dbds.Offset, string.IsNullOrEmpty(pVal.SelectedObjects.GetValue("CardName", 0).ToString()) ? pVal.SelectedObjects.GetValue("CardFName", 0).ToString() : pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                    }
                }
            }
        }

        void B1Form_Storage_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.Before_Action)
            {
            }
            else
            {
                #region  货物信息
                //上一条
                if (pVal.ItemUID == "Previous" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Previous(SBOApp, pVal.FormUID, "@AVA_LN_STG1");
                    Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //下一条
                if (pVal.ItemUID == "Next" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Next(SBOApp, pVal.FormUID, "@AVA_LN_STG1");
                    Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //添加
                if (pVal.ItemUID == "Add" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Add(SBOApp, pVal.FormUID, "@AVA_LN_STG1");
                    Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //删除
                if (pVal.ItemUID == "Del" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CargoCurrentOffset = Utils.Delete(SBOApp, pVal.FormUID, "@AVA_LN_STG1", CargoCurrentOffset);
                    Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                //浏览所有
                if (pVal.ItemUID == "Survey" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    Utils.Survey(SBOApp, SBOCompany, pVal.FormUID, "@AVA_LN_STG1");
                    Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", CargoCurrentOffset);/*货物显示行号、总行数*/
                }
                #endregion

            }
        }
        #endregion

        #region override methods
        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {
            Utils.ShowDBDSNum(CurrentForm, "@AVA_LN_STG1", 0);/*货物显示行号、总行数*/
        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.FormType = B1FormTypes.ado_AVA_LN_Storage;
            FormSetting.FormFileName = "AVA_LN_StorageForm.srf";

            FormSetting.AutoGetObjectNextNumber = false;
            base.FormInfoSetting(FormSetting);
        }

        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {
            base.InitializeForm(InitPar);
            Utils.InitialItemComboBox(SBOCompany, CurrentForm.Items.Item("19"), "Code", "Name", "@AVA_FF_CATY", null, String.Empty, null, true, true);
            //加载用户
            Utils.LoadUser(this.CurrentForm, this.SBOCompany, "7");
            if (!String.IsNullOrEmpty(InitPar.FatherFormUID))
            {
                Form listForm = SBOApp.Forms.Item(InitPar.FatherFormUID.Split(';')[0]);
                Form BNOForm = SBOApp.Forms.Item(listForm.DataSources.UserDataSources.Item("ParentUID").Value);
            }
        }
        #endregion

        #region private methods
        #endregion
    }
}
